
// Copyright (C) 2007 Richard Uhler
// This file is part of Esiply.
//
// Esiply is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License, Version 2,
// as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

#ifndef _SCOPE_H_
#define _SCOPE_H_
//#define GC_THREADS
// Each execution context has a "scope chain". This is an
// ordered set of objects used to keep track of variables
// and functions in scope. The Scope class will encapsulate
// that. It holds the current variable object (reference) and a pointer
// to the next scope up. 
//#include <gc_cpp.h>

class Object;
class String;
class Value;

class Scope  
{
public:

    // Initialize a scope object with no parent, and no variable
    // object. These must be set explicitly before the scope
    // is useful for anything at all.
    Scope(Scope* parent, Object* variable, Value* this_obj);

    // Look through the entire scope chain for the first
    // occurence of the  given identifier. Return
    // a reference to the resulting object.
    Value* lookup(String* identifier);

    Value* get_this() const;
    Object* get_variable() const;

private:
    Scope(const Scope& rhs);
    Scope& operator=(const Scope& rhs);

    Scope* m_parent;
    Object* m_variable;
    Value* m_this;
};

#endif//_SCOPE_H_

